package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    //查询所有护理等级
    @Override
    public List<NursingLevelVo> getAll() {
        List<NursingLevelVo> nursingLevelVos = nursingLevelMapper.getAll();
        return nursingLevelVos;
    }

    //分页展示护理等级
    @Override
    public PageResponse<NursingLevelVo> listByPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevelVo> page = nursingLevelMapper.listByPage(pageNum, pageSize, name, status);
        PageResponse<NursingLevelVo> pageResponse = new PageResponse<>(page);
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }
//系新增护理等级
    @Override
    public void insert(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.insert(nursingLevel);
    }
//通过ID查询
    @Override
    public NursingLevel getById(Long id) {
       NursingLevel nursingLevel= nursingLevelMapper.getById(id);
        return nursingLevel;
    }
//更新
    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        //转换一下类型来接收
                   NursingLevel nursingLevel=BeanUtil.toBean(nursingLevelDto,NursingLevel.class);
                   //最后输出
                   nursingLevelMapper.update(nursingLevel);

    }
//删除
    @Override
    public void delete(Long id) {
      nursingLevelMapper.delete(id);
    }


}
